package cn.northsea.mapper;

import cn.northsea.pojo.*;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;


@Repository
public interface LogisticsMapper {

    List<LogisticsVo> logistics(@Param("likename") String likename);
//    @Update("UPDATE erp_logistics cs SET cs.status=#{number} WHERE cs.logistics_id=#{logisticsId}")
    void updateStatu(@Param("logisticsId") Integer logisticsId, @Param("number")Integer number,@Param("date") Date date);
    @Update("<script>UPDATE erp_logistics cs SET cs.status=3 WHERE cs.logistics_id in " +
            "<foreach item='id' index='index' collection='ids' open='(' separator=',' close=')'>" +
            "#{id}" +
            "</foreach> and cs.status=2 </script>")
    void updateStatuArr(@Param("ids")String[] ids);

    LogisticsVo tanchuang(Integer id);
    @Select("select * from erp_transport_personnel  ")
    List<TransportPersonnel> driver();

    List<LogisticsVo> findAll3();
    @Update("UPDATE erp_logistics SET start_point = #{logistics.startPoint}, end_point =  #{logistics.endPoint}, departure_time = null, arrival_time = null, status =-1, item_Description =  #{logistics.itemDescription}, remarks =  #{logistics.remarks}, transport_personnel_id =  #{logistics.transportPersonnelId} WHERE logistics_id =  #{logistics.logisticsId} ")
    void updateLogistics(@Param("logistics") Logistics logistics);

    List<Order> Order(@Param("likename")String likename);
    @Select("SELECT user_username FROM erp_order r INNER JOIN erp_user u ON u.user_id=r.order_uid WHERE r.order_id=#{id}")
    String selectUsername(Integer id);
    @Select(" SELECT * FROM erp_order where order_id=#{id}")
    Order selectRessPhone(Integer id);
    @Select("SELECT warehouse_address FROM erp_order r INNER JOIN erp_warehousein sein ON sein.product_id=r.order_pid INNER JOIN erp_warehouse se  ON se.warehouse_id=sein.warehouse_id WHERE r.order_id=#{id}")
    String seleAddware(Integer id);
    @Select("SELECT u.user_phone \n" +
            "FROM erp_user u \n" +
            "INNER JOIN erp_user_role ur ON u.user_id = ur.user_id\n" +
            "INNER JOIN erp_role r ON r.role_id = ur.role_id\n" +
            "WHERE r.role_name = '仓库'\n" +
            "LIMIT 1;")
    String slelctWarePhonr();
    @Select("SELECT u.user_username \n" +
            "FROM erp_user u \n" +
            "INNER JOIN erp_user_role ur ON u.user_id = ur.user_id\n" +
            "INNER JOIN erp_role r ON r.role_id = ur.role_id\n" +
            "WHERE r.role_name = '仓库'\n" +
            "LIMIT 1")
    String sleectname();
    @Select("SELECT pro.* FROM erp_order er INNER JOIN erp_product pro ON pro.product_id=er.order_pid WHERE  er.order_id=#{id}")
    Product selectProduct(Integer id);
    @Insert("INSERT INTO erp_logistics ( logistics_id,start_point,end_point,departure_time, arrival_time,status, item_Description, remarks, transport_personnel_id, order_id) VALUES ( null, #{startPoint},  #{endPoint}, null,  null,  -1,  #{itemDescription}, #{remarks}, #{transportPersonnelId}, #{orderId})")
    void addlogistics(Logistics logistics);
    @Update("UPDATE erp_order SET  order_state =#{state} WHERE order_id =  #{orderId} ")
    void UpdateOrderStatu(@Param("orderId") int orderId,@Param("state")int state);
    @Select("SELECT order_id FROM erp_logistics WHERE logistics_id =  #{logisticsId}")
    int seleOrder(Integer logisticsId);
//    @Update("UPDATE erp_logistics cs SET cs.status=3 WHERE cs.logistics_id in (#{ids})")
//    void updateStatuArr(@Param("ids") String[] ids);
}
